package com.xz.arzon.dao.impl;

import com.xz.arzon.bean.Actress;
import com.xz.arzon.bean.Arzon;
import com.xz.arzon.dao.ArzonDao;
import org.mybatis.spring.SqlSessionTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by YLZX-Z0107 on 2014/7/18.
 */
public class ArzonDaoImpl implements ArzonDao {
    public SqlSessionTemplate sqlSession;

    @Override
    public int saveArzon(Arzon arzon) {
        return sqlSession.insert(getClass().getName() + ".saveArzon", arzon);
    }

    @Override
    public int saveArzonImages(int aid, List<String> images) {
        Map param = new HashMap();
        param.put("aid", aid);
        param.put("images", images);
        return sqlSession.insert(getClass().getName() + ".saveArzonImages", param);
    }

    @Override
    public int saveArzonUU(Actress actress) {
        return sqlSession.insert(getClass().getName() + ".saveArzonUU", actress);
    }

    @Override
    public int saveArzonName(int aid, List<Integer> uids) {
        Map param = new HashMap();
        param.put("aid", aid);
        param.put("uids", uids);
        return sqlSession.insert(getClass().getName() + ".saveArzonName", param);
    }

    @Override
    public Actress getByName(String name, Integer id) {
        Map param = new HashMap();
        param.put("id", id);
        param.put("name", name);
        return (Actress) sqlSession.selectOne(getClass().getName() + ".getByName", param);
    }

    @Override
    public Arzon getById(int id) {
        return (Arzon) sqlSession.selectOne(getClass().getName() + ".getById", id);
    }

    @Override
    public List<String> getImages(int aid) {
        return (List<String>) sqlSession.selectList(getClass().getName() + ".getImages", aid);
    }

    @Override
    public List<Actress> getActress(int aid) {
        return (List<Actress>) sqlSession.selectList(getClass().getName() + ".getActress", aid);
    }

    @Override
    public List<Arzon> getByActressId(int uid) {
        return (List<Arzon>) sqlSession.selectList(getClass().getName() + ".getByActressId", uid);
    }

    @Override
    public List<Arzon> getByPage(int offset, int limit) {
        Map map = new HashMap();
        map.put("offset", offset);
        map.put("limit", limit);
        return (List<Arzon>) sqlSession.selectList(getClass().getName() + ".getByPage", map);
    }

    public void setSqlSession(SqlSessionTemplate sqlSession) {
        this.sqlSession = sqlSession;
    }
}
